import axios from "axios";

// 创建一个axios的实例
const request = axios.create({
  baseURL: "/api",
  timeout: 5000,
});

// 配置请求拦截器
request.interceptors.request.use(
  (config) => {
    config.headers.cookie =
      "_ga=GA1.2.538801473.1615773695; _gid=GA1.2.1203902327.1627264055; passport_csrf_token_default=8f00e13f0ce186904862d1e141856684; passport_csrf_token=8f00e13f0ce186904862d1e141856684; n_mh=HDiLtp50ylQ1fFVGsLLBs_n5tG8mRL-CHSCpEVuPtY0; odin_tt=4c430f4b13c93ed235586d97a5d4cd41fe9ffb564477c294e5c0f504453e8d775cee6c3d27e65644a6e9cc73616cfdb48358e7b0f01435dee86d115bdf3b1eac; passport_auth_status=499a8cdd0ebc4902cc3388c65273c3e3%2C704816998991fee61625696982170d89; passport_auth_status_ss=499a8cdd0ebc4902cc3388c65273c3e3%2C704816998991fee61625696982170d89; sid_guard=64909d10e44b9e11f6b89481ed16a718%7C1627270019%7C5184000%7CFri%2C+24-Sep-2021+03%3A26%3A59+GMT; uid_tt=f51160dd4c3e0594c72b2ed63b9050c5; uid_tt_ss=f51160dd4c3e0594c72b2ed63b9050c5; sid_tt=64909d10e44b9e11f6b89481ed16a718; sessionid=64909d10e44b9e11f6b89481ed16a718; sessionid_ss=64909d10e44b9e11f6b89481ed16a718; MONITOR_WEB_ID=acca7c8f-1f98-410c-93e4-07b113fd5ed5";
    return config;
  },
  (error) => {
    console.log(error); // 发生错误打印
    return error;
  }
);

request.interceptors.response.use(
  (config) => {
    return config.data; // 成功直接返回
  },
  (error) => {
    return error;
  }
);

export default request;
